package org.jseda;

import java.util.ArrayList;
import java.util.List;

/**
 * The Publisher broadcasts units of work to its registered listeners.
 *n
 * @author jmcnair
 *
 * @param <T> the type of work handled by this Publisher
 */
public class Publisher<T>
{
  private List<WorkListener<T>> _workListeners = new ArrayList<WorkListener<T>>();

  /**
   * Publish a unit of work to all registered listeners.
   *
   * @param workUnit the unit of work to publish
   */
  public void publishWork(T workUnit)
  {
    for (WorkListener<T> workListener : _workListeners)
      workListener.sendWork(workUnit);
  }

  /**
   * Register a WorkListener.
   *
   * @param workListener the WorkListener to register
   */
  public void registerListener(WorkListener<T> workListener)
  {
    _workListeners.add(workListener);
  }
}
